package ls.cloud.conf;

import ls.cloud.GRpcServerBuilderConfigurer;
import ls.cloud.GRpcServerRunner;
import ls.cloud.GRpcService;
import ls.cloud.register.RpcRegisterManager;
import ls.cloud.register.ZkRpcManager;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by Administrator on 2016/12/28 0028.
 */
@Configuration
@EnableConfigurationProperties(value = {GRpcServerProperties.class, ZkProperties.class})
@AutoConfigureOrder
public class GRpcAutoConfiguration {


    @Bean
    @ConditionalOnBean(annotation = GRpcService.class)
    public GRpcServerRunner grpcServerRunner(GRpcServerBuilderConfigurer configurer) {
        return new GRpcServerRunner(configurer);
    }

    @Bean
    @ConditionalOnMissingBean(GRpcServerBuilderConfigurer.class)
    public GRpcServerBuilderConfigurer serverBuilderConfigurer() {
        return new GRpcServerBuilderConfigurer();
    }


    @Bean
    @ConditionalOnBean(annotation = GRpcService.class)
    public RpcRegisterManager rpcRegisterManager() {
        return new ZkRpcManager();
    }
}
